﻿<!DOCTYPE html>
<html>
<head>
    <!--<base href="../" />-->
    <meta charset="UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="/static/css/common/reset.css" />
    <link rel="stylesheet" href="/static/css/associate.css" />
    <link rel="stylesheet" href="/static/css/sweetalert.min.css" />
    <link rel="stylesheet" href="/static/js/simditor/styles/simditor.css" />
    <link rel="stylesheet" href="/static/js/simditor/styles/simditor-html.css" />
    <title>修改头像</title>
</head>
<body>
    <div class="associate" ng-app="myApp">
        <div id="divHeader"></div>
        <section class="assoc-content container clearfix">
            <div class="assoc-c-left fl">
                <div id="divNavigation"></div>
            </div>
            <div class="assoc-c-right fr" ng-controller="Ctrl">
                <form id="form">
                    <h1 class="f14 mb20">修改头像</h1>
                    <div class="headImg clearfix" ng-model="names">
                        <div class="uploadHeadImg fl">
                            <img src="{{names.LogoPath}}" id="inputImg">
                        </div>
                        <div class="headImgText fl">
                            <h3 class="up-fileNameBook">
                                <label>已添加附件：</label>
                                <input type="text" class="up-file-content" />
                            </h3>
                            <a href="javascript:;" class="up-fileBook" id="up-fileImg">
                                浏览
                                <input type="file" name="logo" id="up-fileImgIn" required>
                            </a>
                            <input type="button" id="btnSubmit" value="保 存" class="headImgSave" />
                        </div>

                    </div>

                </form>
            </div>
        </section>
    </div>
    <div id="divFooter"></div>
    <script type="text/javascript" src="/static/js/ref/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="/static/js/self/common.js"></script>
    <script type="text/javascript" src="/static/js/ref/angular.min.js"></script>
    <script src="/static/js/ref/linq.min.js"></script>
    <script src="/static/js/ref/jquery.validate.js"></script>
    <script type="text/javascript" src="/static/js/ref/sweetalert.min.js"></script>
    <script>
        //选择文件
        /*$("#up-fileImg").on('change', function () {
            var filePath = document.getElementById("up-fileImgIn").files;
            var files_val = '';
            if (filePath) {
                var fileNameBook = $(this).siblings('.up-fileNameBook');
                files_val = ''
                for (var i = 0; i < filePath.length; i++) {
                    files_val += filePath[i].name
                }
                fileNameBook.find('.up-file-content').val(files_val);
                fileNameBook.show()
            }
        });*/

        //设置个人信息选择文件
        $("#up-fileImgIn").on(' change', function () {

            /*var filePath = this.files;
            var files_val = '';
            files_val = "已上传：" + filePath[0].name;
            console.log(filePath);
            this.parentElement.parentElement.nextElementSibling.innerHTML = files_val;*/

            var $file = $(this);
            var fileObj = $file[0];

            var fName = this.value;
            var fileSize = (fileObj.files[0].size / 1024).toFixed(1);
            if (!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(fName)) {
                alert("图片类型必须是.gif,jpeg,jpg,png中的一种")
                return false;
            } else if (fileSize > 1024) {
                alert("图片不能大于1M")
                return false;
            }

            var windowURL = window.URL || window.webkitURL;
            var dataURL;
            var $img = $("#inputImg");
            if (fileObj && fileObj.files && fileObj.files[0]) {
                dataURL = windowURL.createObjectURL(fileObj.files[0]);
                $img.attr('src', dataURL);
            } else {

                dataURL = $file.val();
                var imgObj = document.getElementById("inputImg");
                // 两个坑:
                // 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
                // 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
                imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

            }

        });

        $("#divHeader").load("/wuc/header.html");
        $("#divFooter").load("/wuc/footer.html");
        $("#divNavigation").load("/wuc/navigation.html");

        function AfterCompleted(ctx) {
            if (ctx == null) {
                common.alertMessage("保存失败");
                return;
            }
            common.PutStorageSession("user", JSON.stringify(ctx.ResponseObj));

            ctx = ctx.ResponseObj.UserType;
            debugger;
            if (ctx == "2") {
                window.location = "/personal/associate/commuityinfo.html";
            }
            else if (ctx == "1") {
                window.location = "/company/company/companyinfo.html";
            }
            else if (ctx == "3") {
                window.location = "/agent/agent/commuityinfo.html";
            }
            else {
                common.alertMessage("操作错误");
            }
        }
        common.CreateController({ name: 'Ctrl', url: '/api/User/Get', objType: 'dict' });

        common.ValidateFormJQ('form', 'btnSubmit', submitSecondStep)
        function submitSecondStep() {
            common.FormAjax({ type: 'Post', url: '/api/User/UpdateLogo', ID: "form", sMethod: AfterCompleted });
        };
    </script>
</body>

</html>
